package com.gxuwz.drivemaster;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link TabNewsFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class TabNewsFragment extends Fragment {
    private static final String ARG_TITLE = "title";
    private String title;

    public static TabNewsFragment newInstance(String title) {
        TabNewsFragment fragment = new TabNewsFragment();
        Bundle args = new Bundle();
        args.putString(ARG_TITLE, title);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
        // 根据不同的科目加载不同的布局
        int layoutResId = R.layout.fragment_tab_news; // 默认布局
        
        if (getArguments() != null) {
            title = getArguments().getString(ARG_TITLE);
            switch(title) {
                case "科目一":
                    layoutResId = R.layout.activity_subject_one;
                    break;
                case "科目二":
                    layoutResId = R.layout.fragment_subject_two;
                    break;
                case "科目三":
                    layoutResId = R.layout.fragment_subject_three;
                    break;
                case "科目四":
                    layoutResId = R.layout.fragment_subject_four;
                    break;
            }
        }
        
        View view = inflater.inflate(layoutResId, container, false);
        // 这里可以根据不同科目初始化不同的UI组件
        return view;
    }
}